package com.xxx.dynamicproxy;

public class Test {

	public static void main(String[] args) {
		// 1.创建代理公司
		ProxyCompany proxyCompany = new ProxyCompany();
		
		// 2.代理ManFactory
		ManFactory manFactory = new ManFactoryImpl();
		proxyCompany.setFactory(manFactory);
		ManFactory proxyCompany1 = (ManFactory) proxyCompany.getProxyInstance();
		proxyCompany1.saleManTool("D");
		
		// 3.代理WomanFactory
		WomanFactory womanFactory = new WomanFactoryImpl();
		proxyCompany.setFactory(womanFactory);
		WomanFactory proxyCompany2 = (WomanFactory) proxyCompany.getProxyInstance();
		proxyCompany2.saleWomanTool(1.8f);
		
		// 4.代理ChildFactory
		ChildFactory childFactory = new ChildFactoryImpl();
		proxyCompany.setFactory(childFactory);
		ChildFactory proxyCompany3 = (ChildFactory) proxyCompany.getProxyInstance();
		proxyCompany3.saleToy(10);
		
		// 5.生成字节码文件
		GenerateClassFile.generateClassFile(manFactory.getClass(), proxyCompany1.getClass().getSimpleName());
		GenerateClassFile.generateClassFile(womanFactory.getClass(), proxyCompany2.getClass().getSimpleName());
		GenerateClassFile.generateClassFile(childFactory.getClass(), proxyCompany3.getClass().getSimpleName());
	}

}
